package com;


import java.io.UnsupportedEncodingException;


public class ExampleByteToGb2312OrAscii {

    static public void main(String[] argv) {
        String str = "丁i佳辉9哈2";
        try {
            byte[] byteValue = str.getBytes("gb2312");

            for (int i = 0; i < byteValue.length; i++) {
                if ((byteValue[i] & 0xff) > 0xA0) {
                    byte[] bvChinese = new byte[]{byteValue[i], byteValue[i + 1]};
                    String string = new String(bvChinese, "gb2312");
                    System.out.println(string);
                    i++;
                } else {
                    char c = (char) byteValue[i];
                    String string = String.valueOf(c);
                    System.out.println(string);
                }
            }
            int a = 0;
            a = 0;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

}
